package com.levi.mall.listeners;

import com.google.gson.Gson;
import com.levi.mall.service.OrderService;
import com.levi.pojo.PayInfo;
import com.lly835.bestpay.enums.OrderStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author shentong
 * @since 2022/4/6 9:55 PM
 */
@RabbitListener(queues = "payNotify")
@Slf4j
@Component
public class PayMsgListener {

    @Autowired
    private OrderService orderService;

    @RabbitHandler
    public void process(String msg) {
        log.info("收到了mq消息");
        PayInfo payInfo = new Gson().fromJson(msg, PayInfo.class);
        if (OrderStatusEnum.SUCCESS.name().equals(payInfo.getPlatformStatus())) {
            orderService.paid(payInfo.getOrderNo());
        }
    }
}
